﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;

namespace Galaxy.AutoCAD.Editors
{
    public class LineJig : EntityJig
    {
        Line myline;
        Point3d startpoint;
        Point3d endpoint;
        int count;
        public LineJig() : base(new Line())
        {
            myline = new Line();
            count = 0;
        }
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            JigPromptPointOptions pntops = new JigPromptPointOptions();
            pntops.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoZeroResponseAccepted | UserInputControls.NoNegativeResponseAccepted);
            pntops.UseBasePoint = false;
            pntops.DefaultValue = new Point3d();
            if (count == 0)
            {
                pntops.Message = "\n选择起点";
                PromptPointResult pntres = prompts.AcquirePoint(pntops);
                PromptStatus ss = pntres.Status;
                if (pntres.Status == PromptStatus.OK)
                {
                    startpoint = pntres.Value;
                    endpoint = pntres.Value;//此时实际应该只更新startpoint，但为了便于Update，所以对endpoint也进行了赋值
                    return SamplerStatus.OK;
                }
            }
            if (count == 1)
            {
                pntops.Message = "\n选择终点";
                PromptPointResult pntres = prompts.AcquirePoint(pntops);
                if (pntres.Status == PromptStatus.OK)
                {
                    endpoint = pntres.Value;
                    return SamplerStatus.OK;
                }
                else if (pntres.Status == PromptStatus.Cancel)
                {
                    return SamplerStatus.Cancel;
                }
            }
            return SamplerStatus.Cancel;
        }
        protected override bool Update()
        {
            ((Line)Entity).StartPoint = startpoint;
            ((Line)Entity).EndPoint = endpoint;
            return true;
        }
        public void SetCounter(int i)
        {
            this.count = i;
        }
        public Entity Entity
        {
            get
            {
                return base.Entity;
            }
        }
    }
}